/**
 * Created by JetBrains WebStorm.
 * User: liucw
 * Date: 13-3-10
 * Time: 下午2:12
 * To change this template use File | Settings | File Templates.
 */
function moveElement(elementID,desX,desY,interval){
    //alert(elementID);
    if(!document.getElementById) return false;
    if(!document.getElementById(elementID)) return false;
    var elem = document.getElementById(elementID);
    if(elem.movement){
        clearTimeout(elem.movement);
    }
    if(!elem.style.left){
        elem.style.left = '0px';
    }
    if(!elem.style.top){
        elem.style.top = '0px';
    }
    var xpos = parseInt(elem.style.left);
    var ypos = parseInt(elem.style.top);
    var dist = 0;
    if(xpos == desX && ypos == desY){
        return true;
    }
    if(xpos < desX){
        dist = Math.ceil((desX - xpos)/10);
        xpos = xpos + dist;
    }
    if(xpos > desX){
        dist = Math.ceil((xpos - desX)/10);
        xpos = xpos - dist;
    }
    if(ypos < desY){
        dist = Math.ceil((desY - ypos)/10);
        ypos = ypos + dist;
    }
    if(ypos > desY){
        dist = Math.ceil((ypos - desY)/10);
        ypos = ypos - dist;
    }
    elem.style.left = xpos + 'px';
    elem.style.top = ypos + 'px';
//    var repeat = 'moveElement('+elementID+','+desX+','+desY+','+interval+')';
    var repeat = "moveElement('"+elementID+"',"+desX+","+desY+","+interval+")";
    elem.movement = setTimeout(repeat,interval);
}

function init(){
    if(!document.getElementById) return false;
    if(!document.getElementById('message')) return false;
    var elem = document.getElementById('message');
    elem.style.position = 'absolute';
    elem.style.left = '50px';
    elem.style.top = '100px';

    moveElement('message',200,200,10);
}
//addLoadEvent(init);

